/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-05-28 15:51:32
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-23 10:24:03
 */
import { observable, action } from 'mobx';
import { WeaTools } from 'ecCom';

export default class OdocPrintMouldStore {
  @observable treeDatas = [];
  @observable iframeSrc = '';

  @observable officeType = '';
  @observable requestid = '';
  @observable isIE = '';
  @observable workflowid = '';
  @observable printNodeId = '';
  @observable printMouldid = '';
  @observable selectedKeys = [];
  @observable signFilterlogids = "";


  @action
  getMouldList = (selectValue, workflowid) => {
    const params = {
      selectvalue: selectValue,
      workflowid,
      iseditmould: false,
      isPrintMould: true,
    };
    WeaTools.callApi('/api/odoc/odocSelectMould/getMouldList', 'POST', params).then((data) => {
      if (data.sessionkey) {
        this.getMouldListDatas(data.sessionkey);
      }
    });
  }
  @action
  getMouldListDatas = (sessionkey) => {
    const params = {
      dataKey: sessionkey,
      current: 1,
      sortParams: [],
    };
    WeaTools.callApi('/api/ec/dev/table/datas', 'POST', params).then((data) => {
      let mouldList = [];
      data.datas.forEach((element) => {
        let mouldListDatas = {
          haschild: false,
          isopen: true,
          key: element.id,
          name: element.mouldNamespan,
        };
        mouldList.push(mouldListDatas);
      });
      this.treeDatas = mouldList;
    });
  }
  @action
  getOtherMould = (id) => {
    this.getOdocIframe(this.officeType, this.isIE, this.requestid, this.workflowid, this.printNodeId, id[0], this.signFilterlogids);
    // this.selectedKeys = id;
  }
  @action
  getOdocIframe = (officeType, isIE, requestid, workflowid, printNodeId, printMouldid, signFilterlogids) => {
    this.selectedKeys = [printMouldid];
    this.officeType = officeType;
    this.isIE = isIE;
    this.requestid = requestid;
    this.workflowid = workflowid;
    this.printNodeId = printNodeId;
    this.signFilterlogids = signFilterlogids;

    const params = {
      isIE,
      officeType,
      requestid,
      workflowid,
      printNodeId,
      printMouldid,
      signFilterlogids
    };

    WeaTools.callApi('/api/odoc/officialPrintMould/getPrintMouldOffice', 'POST', params).then((data) => {
      this.iframeSrc = data.officeSrc;
    });
  }

  @action
  printIframe = () => {
    if (this.officeType == 'wpsEditor') {

    } else {
      document.getElementsByClassName('req-printOdocMould')[0].contentWindow.WebOpenPrint();
    }
  }
}
